import request, {post} from "@/utils/request";
import cache from "@/plugins/cache";

// export function uploadPhoto(Mdata) {
//   return request({
//     headers: { "Content-Type": "multipart/form-data", },
//     url: "/system/photo/uploads/" + Mdata.patientId + "/" + Mdata.type + "/" + Mdata.compressionRatio,
//     method: "post",
//     data: Mdata.data,
//     params: { faceLights: Mdata.faceLights, faceParts: Mdata.faceParts, visitNum: Mdata.visitNum, status: Mdata.status, photoUploadTime: Mdata.photoUploadTime },
//     timeout: 600000,
//     // onUploadProgress:config.onUploadProgress
//   });
// }
// export function uploadPhoto(Mdata, fileId, te) {
//   console.log(Mdata)
//   return request({
//     headers: {"Content-Type": "multipart/form-data", repeatSubmit: false},
//     url: "/system/photo/uploads/" + Mdata.patientId + "/" + Mdata.type + "/" + Mdata.compressionRatio,
//     method: "post",
//     data: Mdata.data,
//     params: {
//       faceLights: Mdata.faceLights,
//       faceParts: Mdata.faceParts,
//       visitNum: Mdata.visitNum,
//       status: Mdata.status,
//       photoUploadTime: Mdata.photoUploadTime,
//       uuid: Mdata.uuid,
//       num:Mdata.num,
//     },
//     timeout: 600000,
//     onUploadProgress: (progressEvent) => {
//       if (progressEvent.lengthComputable) {   //是否存在进度
//         let complete = Math.floor(progressEvent.loaded / progressEvent.total * 100)
//         //complete为上传时的进度 0-100
//         let obj = {
//           fileId: fileId,
//           progress: parseInt(progressEvent.loaded / progressEvent.total * 100),
//           isUploaded: false
//         }
//         if(obj.progress>=96){
//           obj.progress=96
//         }
//
//         te.$store.dispatch('file/uploadUploadFile', obj)
//         console.log()
//         console.log('进度:onUploadProgress----',obj.progress, progressEvent)
//       }
//     }
//   });
// }

export function uploadPhoto(Mdata, fileId, te) {
  // console.log(Mdata)
  return post("/system/photo/uploads/" + Mdata.patientId + "/" + Mdata.type + "/" + Mdata.compressionRatio,
    Mdata.data,
    {
      headers: {"Content-Type": "multipart/form-data", repeatSubmit: false},
      params: {
        faceLights: Mdata.faceLights,
        faceParts: Mdata.faceParts,
        visitNum: Mdata.visitNum,
        status: Mdata.status,
        photoUploadTime: Mdata.photoUploadTime,
        uuid: Mdata.uuid,
        num: Mdata.num,
        fileId,
      },
      timeout: 600000,
      onUploadProgress: (progressEvent) => {
        if (progressEvent.lengthComputable) {   //是否存在进度
          let complete = Math.floor(progressEvent.loaded / progressEvent.total * 100)
          //complete为上传时的进度 0-100
          let obj = {
            fileId: fileId,
            progress: parseInt(progressEvent.loaded / progressEvent.total * 100),
            isUploaded: false
          }
          if (obj.progress >= 96) {
            obj.progress = 96
          }

          te.$store.dispatch('file/uploadUploadFile', obj)
          // console.log()
          // console.log('进度:onUploadProgress----', obj.progress, progressEvent)
        }
      }
    });
}

//按照组号删除病人照片
export function delPhotoByGroup(pIndex) {
  return request({
    url: "/system/photo/byPindex/" + pIndex,
    method: "delete",
  });
}


// 查询顾客照片总数
export function getPhotoAllCountByPatientId(patientId) {
  return request({
    url: "/system/photo/count/" + patientId,
    method: "get",
  });
}

// 查询顾客编号照片总数
export function getPhotoAllCountByVisitNum(visitNum) {
  return request({
    url: "/system/photo/countByVisitNum/" + visitNum,
    method: "get",
  });
}

//启动AI模型接口
export function startAi(query) {
  return request({
    url: "/system/photo/start/ai",
    method: "get",
    params: query,
  })
}

///system/photo/pIndex/all/list 查询病人照片列表(查询分析图数据)
export function getpIndexPhotoList(query) {
  return request({
    url: "/system/photo/pIndex/all/list",
    method: "get",
    params: query,
  })
}
//照片列表
export function getFilterPhoto(query) {
  return request({
    url: "/system/photo/photoListTip",
    method: "get",
    params: query,
  })
}

///system/photo/photo/management/query 照片管理查询
export function photoManagement(query) {
  return request({
    url: "/system/photo/photo/management/query",
    method: "get",
    params: query,
  })
}

// /system/photo/annotate/photos 标注照片
export function photoAnnotate(data) {
  return request({
    url: "/system/photo/annotate/photos",
    method: "post",
    data: data,
  })
}
// /system/analysis/list 查询照片艺霏分析记录列表

export function photoAnalysisList(query) {
  return request({
    url: "/system/analysis/list",
    method: "get",
    params: query,
  })
}

// /system/photo/get/Comprehensive  无需登录查询接口（入参体检号或者pindex）：该组照片对应的黄褐斑分析数据+对应此次的诊断及治疗信息
export function getphotoComprehensive(data) {
  return request({
    url: "/system/photo/get/Comprehensive",
    method: "post",
    data: data,
  })
}